Loading data

Weโ€™re gonna look at Instacart data:

library(tidyverse)
library(p8105.datasets)
library(plotly)
data("instacart")

instacart = 
  instacart %>% 
  as_tibble(instacart) %>% 
  select(order_hour_of_day, aisle, department) %>% 
  filter(department %in% c("produce","dairy eggs"))

Plotly plots

Barchart

This is a barchart that shows the number of items ordered in each aisle from Produce or Dairy/Eggs departments (aisles are ordered by ascending number of items).

instacart %>% 
  count(aisle, department) %>% 
  mutate(aisle = fct_reorder(aisle, n)) %>% 
  plot_ly(x = ~aisle, y = ~n, color = ~department, type = "bar", colors = "viridis")

Boxplot

This is a barchart that shows the distribution of order time in hours for each aisle from Produce or Dairy/Eggs departments (aisles are ordered by ascending median order time).

instacart %>% 
  mutate(aisle = fct_reorder(aisle, order_hour_of_day)) %>% 
  plot_ly(x = ~aisle, y = ~order_hour_of_day, color = ~department, type = "box", colors = "viridis")

Line plot

This is a line plot that shows the distribution of the number of items ordered over hours of day, for each aisle from Produce or Dairy/Eggs departments.

instacart %>% 
  count(aisle, order_hour_of_day) %>% 
  plot_ly(x = ~order_hour_of_day, y = ~n, color = ~aisle, type = "scatter", mode = "line", colors = "viridis")